import { UserModel } from "@/database";
import type { User } from "~/type";


/**
 * 用户登录
 * @url /api/v1/login
 * @method POST
 * @param {string} username 用户名
 * @param {string} password 密码
 */
export default defineEventHandler(async (event) => {
    const body = await readBody(event)
    const user = UserModel.find((item) => item.username === body.username && item.password === body.password)
    if (!user) {
        return failApi('用户名或密码错误')
    }
    const { password, ...userOther } = user
    return successApi('登录成功', {
        access_token: user.id.toString(),
        user_info: userOther
    })
})